package org.d5_resourse;

import java.io.*;

public class Test2 {
    public static void main(String[] args) throws Exception {
        InputStream  is = null;
        OutputStream os = null;
        try {
            //需求：复制照片
            //1.创建一个字节输入流管道与源文件接通
         is = new FileInputStream("D:\\idea\\idea code\\java-practice\\practice\\change\\file-oi-app\\src\\filetest3");
            //2.创建一个字节输出流管道与目标文件接通
           os = new FileOutputStream("D:\\idea\\idea code\\java-practice\\practice\\change\\file-oi-app\\src\\copyfiletest3");
            //3.创造一个字节数组，负责转移字节数据
            byte[] buffer = new byte[1024];
            //4.从字节输入流中读取字节数据，写出去到字节输出流中，读多少写出去多少
            int len;//记住每次读取了多少个字节
            while ((len = is.read(buffer)) != -1){
                os.write(buffer,0,len);
            }
            System.out.println("复制完成");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (os != null) os.close();//避免空指针异常
            } catch (Exception e) {
              e.printStackTrace();
            }
            try {
                if (is != null) is.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }
}
